
export const convertBirthday=(date, args) => {
    let dateObj = new Date(date)
    var year = dateObj.getFullYear(),
        month = dateObj.getMonth() + 1,
        day = dateObj.getDay(),
        // h = dateObj.getHours(),
        // m = dateObj.getMinutes(),
        // s = dateObj.getSeconds(),
        month = checkTime(month),
        day = checkTime(day);
        // h = checkTime(h),
        // m = checkTime(m),
        // s = checkTime(s);

    return year + '-' + month + '-' + day 
    // + ' ' + h + ':' + m + ':' + s;


}
export const sexFilter = function(val){
    const sexMapping = {
        M: '男',
        F: '女',
        O: '未知'
      }
      return sexMapping[val]
}

export const ageFilter = function(val){
    const patient_ageTypeMapping = {
        'Y': '岁',
        'M': '月',
        'D': '日',
        'W': '周'
      }
      let patient_ageNum = ''
      let patient_ageType = ''
      if (val) {
        patient_ageNum = val.substring(0, val.length - 1)
        patient_ageType = val.substring(val.length - 1, val.length)
        return patient_ageNum + patient_ageTypeMapping[patient_ageType]
      } else {
        return ''
      }
}

function install(Vue) {
    // v-bind='user.date | birthday
    Vue.filter('birthday', convertBirthday)
    Vue.filter('sex', sexFilter)
    Vue.filter('age', ageFilter)

    

}


function checkTime(i) {
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}


export default {
    install,



}